package com.skeleton.show.control;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.skeleton.db.dto.ShowinfoDto;
import com.skeleton.show.service.ShowService;

/**
 * ShowControl.java
 * 
 * @author Wangyu
 */
@Controller
@RequestMapping("/")
public class ShowControl {

	protected Logger logger = LogManager.getLogger(this.getClass());

	@Resource
	private ShowService showService;

	@RequestMapping("test")
	public String showArticlesDetails(HttpServletRequest request) {
		logger.info("--------------------test--------------------");
		return "index";
	}

	@RequestMapping("login")
	public String login(HttpServletRequest request) {
		logger.info("--------------------login--------------------");
		return "login";
	}

	@RequestMapping("toLogin")
	public String toLogin(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws IOException {
		logger.info("--------------------toLogin--------------------");
		String username = request.getParameter("username");
		String password = request.getParameter("password");

		if (username.equals("admin") && password.equals("123456")) {
			session.setAttribute("user", username);
			response.sendRedirect("admin/admin");
			return null;
		}
		request.setAttribute("msg", "用户名或密码错误");
		return "login";
	}

	@RequestMapping("index")
	public String index(HttpServletRequest request) {
		logger.info("--------------------index--------------------");
		List<ShowinfoDto> list = showService.getAllShow();
		request.setAttribute("list", list);
		return "index";
	}

	@RequestMapping("index3")
	public String index3(HttpServletRequest request) {
		logger.info("--------------------index3--------------------");
		List<ShowinfoDto> list = showService.getAllShow();
		request.setAttribute("list", list);
		return "index3";
	}

}
